package com.sdk.test.exception;

import com.wlyy.framework.dto.response.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = BizException.class)
    public ApiResult handlerBizException(BizException e, HttpServletRequest request) {
        log.error("<<< server-bizException : uri: {}, errorMessage: {}", request.getRequestURI(), e.getMessage());
        return ApiResult.fail(e);
    }

    @ExceptionHandler(value = Exception.class)
    public ApiResult handlerException(Exception e, HttpServletRequest request) {
        log.error("<<< server-bizException : uri: {}, errorMessage: {}", request.getRequestURI(), e.getMessage());
        return ApiResult.fail(-1, e.getMessage());
    }
}
